<template>
	<view class="">
		<!-- #ifdef MP-WEIXIN -->
		<navbar  title="我的收藏" :isGoBack="true" :isNotice="true" :visible="true"  :bgColor="bgColor" :btnColors='btnColor'></navbar>
		<!-- #endif -->	
		
		<view style="display: flex;width: 100%;height: 600rpx" class="flex justify-center align-center text-center" v-if="allTabList.length == 0">
			<u-empty  mode="favor"> </u-empty>
		</view>
		
		
		<swiper class="tab-content"  duration="300" bindchange="changeTab" :style="{'height':winHeight+'px'}">
		    <!-- 全部 -->
			<swiper-item>
				<scroll-view :scroll-y="true" class="new-list-box" @scrolltolower="allLoadMore" scroll-top="scrollTop" scroll-with-animation :refresher-enabled="true" refresher-threshold="80" refresher-default-style="white" refresher-background="white" :refresher-triggered="triggered" @refresherrefresh="onAllRefresh">
					<block v-if="allTabList.length > 0">
						<view class="new-list-item" v-for="(goods,index) in allTabList" :key="index">                        
							<view class="item" >								
							    <image class="grid-img" :src="goods.goods_logo" mode="scaleToFill"></image>								  
							    <view class="cate-zt-main">	
								    <view class="flex justify-between align-center text-center mt-10">
								    	<view class="" style="font-size: 33rpx;">{{goods.goods_title}}</view>
										<view class="" @click="handleDel(goods)">
											<image src="https://image.tea-milk.site/2024-10-10/c9170e006200e0c1e099cfb4b22ac3af.png" mode="scaleToFill" style="width: 60rpx; height: 60rpx;"></image>
										</view>										
								    </view>
									<view class="flex justify-between align-center text-center" style="margin-top: 45rpx;">
										<view class="" style="font-size: 33rpx;color: #518FA0 ;">
											<text style="font-size: 30rpx;margin-left: 5rpx;">¥{{goods.goods_price}}</text>
											<text style="font-size: 30rpx;margin-left: 15rpx;"> 定金：¥{{goods.deposit_price}}</text>
										</view>
										<view class="" @click="showGoods(goods)">
											<u-button type="primary" :plain="true" color="#518FA0" shape="circle" text="查看" size="small" style="width: 120rpx;"></u-button>	
										</view>
									</view>							        
							    </view> 
							</view>
						</view>
					</block>                
				</scroll-view>
			</swiper-item>       
		</swiper>
	</view>	
</template>

<script>	
	export default {
			data() {
				return {
					...getApp().globalData.config,
					cashType:'',
					userInfo:{},
					winHeight:0,
					pageNo:1,
					allTabList:[], // 全部  
					currentTab: 0, // 当前所在滑块的 index
					scrollTop: 0, // 设置竖向滚动条位置
					 triggered: false, // 下拉是否激活
				};
			},
			
			onLoad(options){
				let that=this
				if(options.cashType){
				  this.cashType=options.cashType			  
				}
				let height = uni.getSystemInfoSync().windowHeight;
				this.winHeight = (height - 150);			
				this._requestPageList(true);
			},	
			methods:{	
				//查看商品
				showGoods(item){
					uni.navigateTo({
						url:"/pages/pagesGoods/detail/index?id="+item.goodsId
					})
				},
				//删除
				handleDel(item){
					let that=this			
					uni.showModal({content: '确定删除收藏吗？'}).then(res=>{			
					  if(res.confirm){
						this.$http.delCollect({
							token:uni.getStorageSync('userInfo').token,
							login_type:'app',
							ids:item.id,
						}).then(res=>{
							if(res.resCode=='9999'){
							  uni.showToast({title:res.resMessage,icon:'none'})
							  setTimeout(()=>{
								  this.allTabList=[];
								  this._requestPageList(true);
							  },2000)          
							  return
							}else{
							  uni.showToast(res.resMessage)
							}
						})       
					  }
					})
				},
				docoupon(){
					this.$routers.router('/pages/home/index','switchTab') 
				},
				changeNav(e){
					let currentIndex = e.target.dataset.current;
					if (this.currentTab == currentIndex) {      
					    return false;
					} else {
					    this.pageNo=1;
						this.currentTab= currentIndex
					}
					this.allTabList=[];
					this._requestPageList(true);
				},	
				
				// 参数
				_requestPageList(isLoadMore = false, callback) {
				  if(!isLoadMore){
					this.allTabList=[]; // 全部       
					this.pageNo= 1;
					
				  }
				  let opt = {
					pageNo :this.pageNo,				
					token:uni.getStorageSync('userInfo').token,
				  }    
				  this._requestPageListCom("virtualTaskList", opt, callback);
				},
				// 列表接口
				_requestPageListCom(url, params, callback) {    
				  this.$http.collectList(params).then(res => {
					if (res.resCode == "9999") {
					  let oldList = [];
					  oldList = this.allTabList;       
					  const newGoodsList = res.data.lists
					  const allData = [...oldList, ...newGoodsList]
					  // console.log(allData,'allData')     
					  this.allTabList=allData
					  if(callback && typeof callback === 'function'){
						callback()
					  }
					}
				  })
				},			  
				// 上拉加载  滚动到底部/右边时触发
				allLoadMore(e){
					let _self = this;
					if (this._allLoadMore) return
					this._allLoadMore = true;
					this.pageNo= ++_self.pageNo				
					this._requestPageList(true, () => {
					  _self._allLoadMore = false;
					});
				},
				
				// 下拉刷新接口
				onAllRefresh() {
				 // 开启下拉自定义样式
					this.triggered = true;
	                this.pageNo=1;
					this._requestPageList(false, () => {
						// 当处理完数据刷新后，wx.stopPullDownRefresh可以停止当前页面的下拉刷新
						this.triggered = false;
					});    
				}	
			  },
			onShow(){	
			}
		}	
</script>

<style>
	@import "./index.css";
</style>